/*
 * @Description: 数组元素的平均值
 * @Author: liuzl
 * @Date: 2024-09-04 15:00:07
 * @LastEditors: liuzl
 * @LastEditTime: 2024-09-04 15:41:15
 */
import java.util.Arrays;

public class Test_Average {
    
    public static void main(String[] args) {
        // 手动输入一个数组
        int[] Array = {23, 45, 67, 89, 12, 34, 56, 78, 90, 15};
        System.out.println("手动输入的数组: " + Arrays.toString(Array));
        
        // 计算平均值
        double average = Average(Array);
        System.out.println("平均值: " + average);
    }
    
    // 计算平均值的方法
    public static double Average(int[] array) {
        if (array == null || array.length == 0) {
            return 0.0; // 如果数组为空或长度为0，返回0.0
        }
        
        double sum = 0; 
        // 遍历数组
        for (int i = 0; i<array.length;i++) {
            int num = array[i];
            System.out.print("sum="+sum"+"+num);
            sum += num;
            System.out.println("="+sum);
        }
        return (double) sum / array.length;
    }
}